package com.thb.utils;

import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.imageio.ImageIO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImageUtils {
	
	private static final Logger logger = LoggerFactory.getLogger(ImageUtils.class); 

	private static final String prefix = ".jpg";
	
//	private static final String head_url = "e:/home/";

	public static String getImgWith(String filename) {
		int height;
		int width;
		try {
			InputStream is = new FileInputStream(filename);

			BufferedImage buff = ImageIO.read(is);
			height = buff.getHeight();
			width = buff.getWidth();
			return String.format("%s,%s", height, width);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
			
		}
		return String.format("%s,%s", 0, 0);

	}

	public static String GenerateImage(String imgStr,String headUrl ) {
		Date now = new Date();
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
		String filename = df.format(now);

		String allname = filename + RandomUtils.getRandom(5) + prefix;
		ImageUtil.decodeBase64ToImage(imgStr, headUrl, allname);
		return allname;
	}

}
